package com.learning.pull;

import java.io.FileReader;
import java.util.HashMap;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;

import com.learning.constants.Label;

public class PullXml {

	public static void main(String[] args) {
		String path = "source/games.xml";
		pullParser(path);
		HashMap<String, String> map = new HashMap<String, String>();
		p(map.get(""));
	}

	private static void pullParser(String path) {
		try {
			XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
			XmlPullParser parser = factory.newPullParser();
			parser.setInput(new FileReader(path));
			int type = parser.getEventType();
			while (type != 1) {
				String label = parser.getName();
				switch (type) {
				case 0:// file start
					break;
				case 1:// file end
					break;
				case 2:// label start
					p(2 + "---" + label);
					if (label.equals(Label.GAME_ID)) {
						p("-----" + parser.nextText());
					} else if (label.equals(Label.GAME_NAME)) {
						p("-----" + parser.nextText());
					} else if (label.equals(Label.GAME_COMPANY)) {
						p("-----" + parser.nextText());
					} else if (label.equals(Label.GAME_LABEL)) {
						p("-------------------------value="
								+ parser.getAttributeValue(0));
					}
					break;
				case 3:// label end
					p(3 + "--" + parser.getName());
					p("--------------------------------------------------------------------------");
					break;
				case 4:// return value
					break;

				}
				type = parser.next();
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	static void p(Object o) {
		System.out.println(o);
	}
}
